# Build recipe for moc.
#
# Copyright (c) 2018 Markus Tornow, <tornow@riseup.net>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

program=moc
version=2.5.2	
release=1

# Set 'outdir' for a nice and well-organized output directory
outdir="${outdir}/${arch}/audio"

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=http://ftp.daper.net/pub/soft/moc/stable/"$tarname"

description="
MOC (music on console) is a console audio player for LINUX/UNIX designed to be
powerful and easy to use.

You just need to select a file from some directory using the menu similar to
Midnight Commander, and MOC will start playing all files in this directory
beginning from the chosen file.  There is no need to create playlists as in
other players.

If you want to combine some files from one or more directories in one playlist,
you can do this.  The playlist will be remembered between runs or you can save
it as an m3u file to load it whenever you want.

Need the console where MOC is running for more important things?  Need to close
the X terminal emulator?  You don't have to stop playing - just press q and the
interface will be detached leaving the server running.  You can attach it later,
or you can attach one interface in the console, and another in the X terminal
emulator, no need to switch just to play another file.

MOC plays smoothly, regardless of system or I/O load because it uses the output
buffer in a separate thread.  The transition between files is gapless, because
the next file to be played is precached while the current file is playing.

Supported file formats are: MP3, Ogg Vorbis, FLAC, Musepack (mpc), Speex, Opus,
WAVE, those supported by FFmpeg/LibAV (e.g., WMA, RealAudio, AAC, MP4), AIFF,
AU, SVX, Sphere Nist WAV, IRCAM SF, Creative VOC, SID, wavpack, MIDI and
modplug.
"

homepage=http://moc.daper.net/
license="GPLv2"

# Source documentation
docs="AUTHORS COPYING README NEWS"
docsdir="${docdir}/${program}-${version}"
 
build()
{
    set -e

    unpack "${tardir}/$tarname"

    cd "$srcdir"
   
    autoreconf -fi
    ./configure CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --docdir=$docdir \
     #--build="$(cc -dumpmachine)"
    
    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install

    # Compress info documents deleting index file for the package
    if test -d "${destdir}/$infodir"
    then
        rm -f "${destdir}/${infodir}/dir"
        lzip -9 "${destdir}/${infodir}"/*
    fi

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 '{}' +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}${docsdir}"
    cp -p $docs "${destdir}${docsdir}/"
}


